package com.appkubes.mall.restful.application.pay.strategy.wxapp;

import com.appkubes.common.exception.BusinessException;
import com.appkubes.mall.core.entity.MallOrder;
import com.appkubes.mall.restful.application.order.order.service.OrderService;
import com.appkubes.mall.restful.application.pay.constants.PayConstants;
import com.appkubes.mall.restful.application.pay.entity.dto.PayOrderDTO;
import com.appkubes.mall.restful.application.pay.service.PayService;
import com.appkubes.mall.restful.application.pay.strategy.wxpay.service.WxPayService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @Author: Rongjie
 * @Date: 2020/2/23
 * @Description:
 */
@Service
public class PayWxAppServiceImpl implements PayService {
    @Resource
    WxPayService wxPayService;
    @Resource
    OrderService orderService;


    @Override
    public PayConstants.PaymentType getPaymentType() {
        return PayConstants.PaymentType.WXAPP;
    }

    @Override
    public PayOrderDTO pay(String orderKey) throws BusinessException {
        MallOrder order = orderService.getById(orderKey);
        Map<String, String> result = wxPayService.pay("", order.getPayAmount(), order.getOrderKey(), "Order", "商城购物", "2");
        PayOrderDTO payOrderDTO = new PayOrderDTO();
        payOrderDTO.setPaymentType(PayConstants.PaymentType.WXAPP.name());
        payOrderDTO.setPaymentName("微信APP");
        payOrderDTO.setPayData(result);
        return payOrderDTO;
    }
}
